package com.skydonkey.dao;

import com.skydonkey.pojo.po.VideoCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface VideoCategoryMapper {
    @Insert("INSERT INTO video_category (video_id, category_id) VALUES (#{videoId}, #{categoryId})")
    int insert(VideoCategory videoCategory);

    @Delete("DELETE FROM video_category WHERE video_id = #{videoId} AND category_id = #{categoryId}")
    int delete(@Param("videoId") int videoId, @Param("categoryId") int categoryId);

    // 根据视频id查该视频所属的类别
    @Select("SELECT category_id FROM video_category WHERE video_id = #{videoId}")
    List<VideoCategory> selectCategoryByVideoId(@Param("videoId") int videoId);

    // 根据视频id查该视频所属的类别名称
    @Select("SELECT t1.name from categories as t1 " +
            "right join video_category as t2 " +
            "on t1.category_id = t2.category_id " +
            "where t2.video_id = #{videoId}")
    List<String> selectCategoryNameByVideoId(@Param("videoId") Long videoId);


    // 根据类别id查该类别下的视频id
    @Select("SELECT video_id FROM video_category WHERE category_id = #{categoryId}")
    List<VideoCategory> selectVideoIdByCategory(@Param("categoryId") int categoryId);


    @Delete("DELETE FROM video_category " +
            "WHERE video_id = #{videoId}")
    int deleteVideoCategory(Long videoId);
}
